<template>
<ScrollEl
    class="base-data-view">
    <div 
        class="base-data-container">
        <div class="left-container">
            <ShowBaseData></ShowBaseData>
        </div>
        <div class="right-container">
            <div class="item">
                <div class="title">
                    <img src="../../assets/icon/water1.png" alt="">
                    地层水报告
                </div>
                <div class="chart-container">
                    <MyChart
                        class="chart"
                        ref="MyChart">
                    </MyChart>
                    <div class="data">
                        <div>报告总数：<span>{{(reportNum.water || 0) + (reportNum.wIsotope || 0)}}</span></div>
                        <div>基础报告：<span>{{(reportNum.waterBasic || 0) + (reportNum.wIsotopeBasic || 0)}}</span></div>
                        <div>临时报告：<span>{{(reportNum.waterNobasic || 0) + (reportNum.wIsotopeNobasic || 0)}}</span></div>
                        <div>油气田水报告：<span>{{(reportNum.water || 0)}}</span></div>
                        <div>水中氢氧同位素分析报告：<span>{{(reportNum.wIsotope || 0)}}</span></div>
                    </div>
                </div>
            </div>
            <div class="item">
                <div class="title">
                    <img src="../../assets/icon/steam1.png" alt="">
                    天然气报告
                </div>
                <div class="chart-container">
                    <MyChart
                        class="chart"
                        ref="MyChart1">
                    </MyChart>
                    <div class="data">
                        <div>报告总数：<span>{{(reportNum.steam || 0) + (reportNum.sIsotope || 0)}}</span></div>
                        <div>基础报告：<span>{{(reportNum.steamBasic || 0) + (reportNum.sIsotopeBasic || 0)}}</span></div>
                        <div>临时报告：<span>{{(reportNum.steamNobasic || 0) + (reportNum.sIsotopeNobasic || 0)}}</span></div>
                        <div>天然气组成分析报告：<span>{{(reportNum.steam || 0)}}</span></div>
                        <div>天然气组分碳氢氧同位素分析报告：<span>{{(reportNum.sIsotope || 0)}}</span></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="border border1"></div>
        <div class="border border2"></div>
        <div class="border border3"></div>
        <div class="border border4"></div>
        <div class="border border5"></div>
        <div class="border border6"></div>
        <div class="border border7"></div>
        <div class="border border8"></div>
        <div class="border border9"></div>
    </div>
</ScrollEl>
</template>
<script>
/*
 基础数据页面
 */
import ScrollEl from "@/components/ScrollEl";
import ShowBaseData from "./components/ShowBaseData";
import {computedRem} from "@/common/OtherTools";
import MyChart from '@/components/MyChart';
export default {
    name:'BaseData',
    components:{ScrollEl,ShowBaseData,MyChart},
    data() {
        return {
            fontColor:'',
            borderColor:'',
            chartBorderColor:'',
            loading: false,
            reportNum:{},
        };
    },
    mounted() {
        this.fontColor = getComputedStyle(document.documentElement).getPropertyValue('--font-color');
        this.borderColor = getComputedStyle(document.documentElement).getPropertyValue('--border-color');
        this.chartBorderColor = getComputedStyle(document.documentElement).getPropertyValue('--border-color-chart');
        this.getData();
    },
    methods: {
        getData(){
            this.$Service.get(this.$Api.reportNum)
                .then(data => {
                    let reportNum = data.data || {};
                    this.reportNum = reportNum;
                    this.drawChart({
                        target:this.$refs.MyChart,
                        data:{
                            title:'地层水',
                            list:[
                                // {value:(reportNum.water || 0) + (reportNum.wIsotope || 0),name:'报告总数'},
                                {value:(reportNum.waterBasic || 0) + (reportNum.wIsotopeBasic || 0),name:'基础报告'},
                                {value:(reportNum.waterNobasic || 0) + (reportNum.wIsotopeNobasic || 0),name:'临时报告'},
                                {value:(reportNum.water || 0),name:'油气田水报告'},
                                {value:(reportNum.wIsotope || 0),name:'水中氢氧同位素分析报告'},
                            ],
                        },
                    });
                    this.drawChart({
                        target:this.$refs.MyChart1,
                        data:{
                            title:'天然气',
                            list:[
                                // {value:(reportNum.steam || 0) + (reportNum.sIsotope || 0),name:'报告总数'},
                                {value:(reportNum.steamBasic || 0) + (reportNum.sIsotopeBasic || 0),name:'基础报告'},
                                {value:(reportNum.steamNobasic || 0) + (reportNum.sIsotopeNobasic || 0),name:'临时报告'},
                                {value:(reportNum.steam || 0),name:'天然气组成分析报告'},
                                {value:(reportNum.sIsotope || 0),name:'天然气组分碳氢氧同位素分析报告'},
                            ],
                        },
                    });
                })
                .finally(() => {
                    this.loading = false;
                });
        },
        drawChart({target,data={}}){  //绘制表格
            let rem = computedRem();
            let list = data.list;
            var option = {
                grid: {
                    left: '30px',
                    right: '5%',
                    top: '10%',
                    bottom: '10%',
                },
                tooltip: {
                    trigger: 'item',
                    formatter: params=>{
                        return `${params.name}:${params.value}`;
                    },
                },
                xAxis: {
                    type: 'category',
                    data: list.map(item=>{
                        return item.name;
                    }),
                    nameTextStyle:{
                        fontWeight:'bold',
                        fontSize:1*rem,
                    },
                    splitArea: {
                        show: false,
                    },
                    splitLine: {
                        show: false,
                    },
                    // table:{
                    //     formatter(params){
                    //         return `${params.name.substring(0,8)}\n\n${params.name.substring(8)}`;
                    //     },
                    // },
                    axisLine: {
                        show:true,
                        lineStyle: {
                            color:this.fontColor,
                        },
                        onZero:false,
                    },
                    axisLabel:{  //x轴的标签设置
                        show:true,
                        lineStyle: {
                            color:this.fontColor,
                        },
                    },
                },
                yAxis: {
                    type: 'value',
                    min:0,
                    max:this.reportNum.reportNum,
                    splitArea: {
                        show: false,
                    },
                    axisLine: {
                        show:false,
                        lineStyle: {
                            color:this.fontColor,
                        },
                        onZero:false,
                    },
                    splitLine: {//分割线配置
                        show:true,
                        lineStyle: {
                            color: this.chartBorderColor,
                        }
                    },
                },
                series: [
                    {
                        data:list.map(item=>{
                            return {
                                value:item.value,
                                // itemStyle:{
                                //     color:this.nameConfigMap[item.horizon].color,
                                // },
                                label: {
                                    show: true, //开启显示
                                    position: 'top', //在上方显示
                                    textStyle: { //数值样式
                                        color: this.fontColor,
                                        fontSize: 14,
                                        fontWeight: 600
                                    }
                                }
                            };
                        }),
                        barWidth : 50,//柱图宽度
                        type: 'bar',
                        itemStyle: {
                            color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                // { offset: 0, color: '#2278f9' },
                                // { offset: 0.5, color: '#042b5e' },
                                // { offset: 1, color: '#031c2d' }
                                { offset: 0, color: '#305ef3' },
                                { offset: 0.5, color: '#043890' },
                                { offset: 1, color: '#121994' }
                            ])
                        },
                    }
                ],
            };
            target && target.setOption(option);
        },
    },
};
</script>
<style lang="scss" scoped>
.base-data-view{
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    >.base-data-container {
        width: 100%;
        height: fit-content;
        padding: 1rem;
        border-radius: 8px;
        border: 2px solid transparent;
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-gap: 15px;
        box-sizing: border-box;
        box-shadow: inset 0px 0px 150px #073d45;
        position: relative;
        margin-top: 30px;
        >.left-container{
            overflow: auto;
            max-height: 70vh;
        }
        >.right-container{
            display: grid;
            grid-template-rows: 1fr 1fr;
            grid-gap: 1rem;
            color: white;
            >.item{
                display: grid;
                grid-gap: 0px;
                >.title{
                    font-size: 20px;
                    display: flex;
                    align-items: center;
                    img{
                        margin-right: 5px;
                    }
                }
                >.chart-container{
                    display: grid;
                    grid-template-columns: 1fr 240px;
                    >.chart{
                        width: 100%;
                        height: 20rem;
                    }
                    >.data{
                        display: grid;
                        background-color: rgba(255, 255, 255, 0.076);
                        border-radius: 8px;
                        height: fit-content;
                        padding: 20px;
                        grid-gap: 15px;
                        font-size: 13px;
                        span{
                            font-size: 17px;
                            color: #FF7919;
                            font-weight: bold;
                        }
                    }
                }
            }
        }
        >.border{
            position: absolute;
        }
        >.border1{
            height: 28px;
            width: 28px;
            top: -2px;
            left: -2px;
            background-image: url(../../assets/icon/border6.png);
        }
        >.border2{
            height: 28px;
            width: 28px;
            top: -2px;
            right: -2px;
            background-image: url(../../assets/icon/border4.png);
        }
        >.border3{
            height: 28px;
            width: 28px;
            bottom: -2px;
            right: -2px;
            background-image: url(../../assets/icon/border5.png);
        }
        >.border4{
            height: 28px;
            width: 28px;
            bottom: -2px;
            left: -2px;
            background-image: url(../../assets/icon/border7.png);
        }
        >.border5{
            height: 100%;
            width: 1px;
            top: 0px;
            left: -2px;
            background-image: url(../../assets/icon/border1.png);
            z-index: 1;
        }
        >.border6{
            height: 100%;
            width: 1px;
            top: 0px;
            right: -2px;
            background-image: url(../../assets/icon/border1.png);
            z-index: 1;
        }
        >.border7{
            height: 4px;
            width: 100%;
            top: -2px;
            left: 0;
            background-image: url(../../assets/icon/border3.png);
            background-position: center;
        }
        >.border8{
            height: 4px;
            width: 100%;
            bottom: -2px;
            left: 0;
            background-image: url(../../assets/icon/border3.png);
            background-position: center;
        }
        >.border9{
            height: 79px;
            width: 147px;
            top: -41px;
            right: 50px;
            background-image: url(../../assets/icon/border2.png);
        }
    }
}
</style>
